package containerdepth;

import java.util.AbstractMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class MyMapTest extends AbstractMap<String, String> {

	private static String[] ch = "he lo weo dkn qlk cld ei".split(" ");
	private int size;
	public MyMapTest(int s){
		size = s;
	}
	private static class MyEntry implements Map.Entry<String, String>{
		private String key;
		private String value;
		
		public MyEntry(String k,String v){
			key = k;
			value = v;
		}
		@Override
		public String getKey() {
			return key;
		}

		@Override
		public String getValue() {
			return value;
		}

		@Override
		public String setValue(String v) {
			// TODO Auto-generated method stub
			this.value = v;
			return this.value;
		}
		public String toString(){
			return key+"==="+value;
		}
	}
	@Override
	public Set<java.util.Map.Entry<String, String>> entrySet() {
		// TODO Auto-generated method stub
		Set<Map.Entry<String, String>> set = new HashSet<Map.Entry<String, String>>();
		for(int i = 0;i<size;i++){
			set.add(new MyEntry(""+i,ch[i%ch.length]));
		}
		return set;
	}
	public String toString(){
		Iterator<Map.Entry<String, String>> it = entrySet().iterator();
		StringBuffer s = new StringBuffer();
		if(it == null){
			return "{}";
		}
//		System.out.println("{");
		s.append("{");
		while(it.hasNext()){
			Map.Entry<String, String> m = it.next();
//			System.out.println(m);
			s.append(m+",");
		}
//		System.out.println("}");
		s.append("}");
		return s.toString();
	}
}
